"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameWebReqHandler = void 0;
const Logger_1 = require("../engine/utils/Logger");
const Md5Helper_1 = require("../engine/utils/Md5Helper");
const WebUtil_1 = require("../engine/utils/WebUtil");
const routerMap = {};
class GameWebReqHandler {
    init(app) {
        for (const key in routerMap) {
            app.use(routerMap[key], this.onBaseRoot.bind(this));
        }
    }
    onBaseRoot(req, resp) {
        try {
            let ip = WebUtil_1.WebUtil.getIpByExpressReq(req);
        }
        catch (error) {
            Logger_1.Logger.warn("onBaseRoot error", error);
        }
    }
    checkBody(ip, req, resp, callback) {
        if (req.body) {
            try {
                let jsonObj = JSON.parse(req.body);
                let k = jsonObj["k"];
                let data = jsonObj["data"];
                if (k == Md5Helper_1.Md5Helper.getMd5_encrypt(JSON.stringify(data))) {
                    callback && callback(req, resp, data, ip);
                }
                else {
                    Logger_1.Logger.error("收到非法Http请求 key", ip, req.body);
                    resp.end();
                }
            }
            catch (error) {
                Logger_1.Logger.error("收到非法Http请求body", ip, req.body, error);
                resp.end();
            }
        }
        else {
            resp.end();
        }
    }
}
exports.GameWebReqHandler = GameWebReqHandler;
GameWebReqHandler.instance = new GameWebReqHandler();
